#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <stack>
#include <cstring>
#include <queue>
#include <cctype>
#include <iomanip>
#include <climits>
#include <array>

using i64 = signed long long;

constexpr int N = 5E5 + 5, M = 2E5 + 5;
constexpr int INF = 0x3f3f3f3f;

using Edge = std::array<int, 3>;

Edge edge[M];

int p[N];

int find(int x) {
    if (p[x] != x) {
        p[x] = find(p[x]);
    }
    return p[x];
}


int kruskal(int n, int m) {
    for (int i = 0; i <= n; ++i) {
        p[i] = i;
    }
    int cnt = 0;
    i64 re = 0;
    std::sort(edge, edge + m);
    for (int i = 0; i < m; ++i) {
        auto [w, u, v] = edge[i];
        int x = find(u), y = find(v);
        if (x == y) {
            continue;
        }
        p[x] = y;
        ++cnt;
        re += w;
    }
    if (cnt != n - 1) {
        return -1;
    }
    return re;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, m;
    std::cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int u, v, w;
        std::cin >> u >> v >> w;
        edge[i] = {w, u, v};
    }

    auto re = kruskal(n, m);
    if (re == -1) {
        std::cout << "orz\n";
    } else {
        std::cout << re << "\n";
    }

    return 0;
}
